######################################
# 时空接口测试
#####################################

from pprint import pprint
import requests
import json


class ShiKong():

    def __init__(self):
        # 登录
        self.login()

    def login(self):
        headers = None
        data = {
            'username': 'admin',
            'password': '0000'
        }
        r = requests.post('http://60.174.109.246:7980/Api/Login',
                          headers=headers,
                          data=data)
        if (r.status_code == 200):
            d = json.loads(r.text)
            state = d['state']
            if state == 'success':
                self.sessionId = d['message']
            else:
                pprint('登录接口返回异常state', state)
        else:
            pprint('登录接口返回异常')

    def downData(self):
        headers = None
        data = {
            'sessionId': self.sessionId,
            'ApiMethod': 'DownGoods',
            'ApiParams': {
                'updateTime': '2020-01-01',
                'orgCode': None,
                'page': 100,
                'rows': 1
            }
        }
        r = requests.post('http://60.174.109.246:7980/Api/DownData',
                          headers=headers,
                          data=data)
        pprint(r.text)


if __name__ == '__main__':
    sk = ShiKong()
    sk.downData()
